        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>Sweep class / box2d Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d" data-type="Sweep">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d.html">box2d</a> &rsaquo; <a href="../box2d/Sweep.html">Sweep</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>Sweep</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class Sweep {
 /** Local center of mass position. */
 final vec2 localCenter;

 /** Center world positions. */
 final vec2 centerZero;
 final vec2 center;

 /** World angles. */
 num angleZero;
 num angle;

 /**
  * Constructs a new Sweep with centers initialized to the origin and angles
  * set to zero.
  */
 Sweep() :
   localCenter = new vec2.zero(),
   centerZero = new vec2.zero(),
   center = new vec2.zero(),
   angleZero = 0,
   angle = 0;

 /**
  * Constructs a new sweep that is a copy of the given Sweep.
  */
 Sweep.copy(Sweep other)
     : localCenter = new vec2.copy(other.localCenter),
       centerZero = new vec2.copy(other.centerZero),
       center = new vec2.copy(other.center),
       angleZero = other.angleZero,
       angle = other.angle;

 /**
  * Returns true if given object is equal to this sweep. Two sweeps are equal
  * if their fields are equal.
  */
 bool operator ==(other) {
   return localCenter == other.localCenter &amp;&amp; centerZero == other.centerZero
       &amp;&amp; center == other.center &amp;&amp; angleZero == other.angleZero &amp;&amp;
       angle == other.angle;
 }

 /**
  * Sets this Sweep equal to the given Sweep.
  */
 void setFrom(Sweep other) {
   localCenter.copyFrom(other.localCenter);
   centerZero.copyFrom(other.centerZero);
   center.copyFrom(other.center);
   angleZero = other.angleZero;
   angle = other.angle;
 }

 void normalize() {
   num d = MathBox.TWO_PI * (angleZero / MathBox.TWO_PI).floor();
   angleZero -= d;
   angle -= d;
 }

 /**
  * Computes the interpolated transform at a specific time.
  * Time is the normalized time in [0,1].
  */
 void getTransform(Transform xf, num alpha) {
   assert (xf != null);

   xf.position.x = (1.0 - alpha) * centerZero.x + alpha * center.x;
   xf.position.y = (1.0 - alpha) * centerZero.y + alpha * center.y;
   xf.rotation.setRotation((1.0 - alpha) * angleZero + alpha * angle);

   // Shift to origin
   xf.position.x -= xf.rotation.col0.x * localCenter.x + xf.rotation.col1.x
       * localCenter.y;
   xf.position.y -= xf.rotation.col0.y * localCenter.x + xf.rotation.col1.y
       * localCenter.y;
 }

 /**
  * Advances the sweep forward, resulting in a new initial state.
  * Time is the new initial time.
  */
 void advance(num time) {
   centerZero.x = (1 - time) * centerZero.x + time * center.x;
   centerZero.y = (1 - time) * centerZero.y + time * center.y;
   angleZero = (1 - time) * angleZero + time * angle;
 }
}
</pre>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="Sweep">
<button class="show-code">Code</button>
new <strong>Sweep</strong>() <a class="anchor-link" href="#Sweep"
              title="Permalink to Sweep.Sweep">#</a></h4>
<div class="doc">
<p>Constructs a new Sweep with centers initialized to the origin and angles
set to zero.</p>
<pre class="source">
Sweep() :
 localCenter = new vec2.zero(),
 centerZero = new vec2.zero(),
 center = new vec2.zero(),
 angleZero = 0,
 angle = 0;
</pre>
</div>
</div>
<div class="method"><h4 id="Sweep.copy">
<button class="show-code">Code</button>
new <strong>Sweep.copy</strong>(<a href="../box2d/Sweep.html">Sweep</a> other) <a class="anchor-link" href="#Sweep.copy"
              title="Permalink to Sweep.Sweep.copy">#</a></h4>
<div class="doc">
<p>Constructs a new sweep that is a copy of the given Sweep.</p>
<pre class="source">
Sweep.copy(Sweep other)
   : localCenter = new vec2.copy(other.localCenter),
     centerZero = new vec2.copy(other.centerZero),
     center = new vec2.copy(other.center),
     angleZero = other.angleZero,
     angle = other.angle;
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field"><h4 id="angle">
<button class="show-code">Code</button>
num         <strong>angle</strong> <a class="anchor-link"
            href="#angle"
            title="Permalink to Sweep.angle">#</a>
        </h4>
        <div class="doc">
<pre class="source">
angle
</pre>
</div>
</div>
<div class="field"><h4 id="angleZero">
<button class="show-code">Code</button>
num         <strong>angleZero</strong> <a class="anchor-link"
            href="#angleZero"
            title="Permalink to Sweep.angleZero">#</a>
        </h4>
        <div class="doc">
<pre class="source">
angleZero
</pre>
</div>
</div>
<div class="field"><h4 id="center">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>center</strong> <a class="anchor-link"
            href="#center"
            title="Permalink to Sweep.center">#</a>
        </h4>
        <div class="doc">
<pre class="source">
center
</pre>
</div>
</div>
<div class="field"><h4 id="centerZero">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>centerZero</strong> <a class="anchor-link"
            href="#centerZero"
            title="Permalink to Sweep.centerZero">#</a>
        </h4>
        <div class="doc">
<pre class="source">
centerZero
</pre>
</div>
</div>
<div class="field"><h4 id="localCenter">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>localCenter</strong> <a class="anchor-link"
            href="#localCenter"
            title="Permalink to Sweep.localCenter">#</a>
        </h4>
        <div class="doc">
<pre class="source">
localCenter
</pre>
</div>
</div>
</div>
<div>
<h3>Operators</h3>
<div class="method"><h4 id="==">
<button class="show-code">Code</button>
bool <strong>operator ==</strong>(other) <a class="anchor-link" href="#=="
              title="Permalink to Sweep.operator ==">#</a></h4>
<div class="doc">
<p>Returns true if given object is equal to this sweep. Two sweeps are equal
if their fields are equal.</p>
<pre class="source">
bool operator ==(other) {
 return localCenter == other.localCenter &amp;&amp; centerZero == other.centerZero
     &amp;&amp; center == other.center &amp;&amp; angleZero == other.angleZero &amp;&amp;
     angle == other.angle;
}
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="advance">
<button class="show-code">Code</button>
void <strong>advance</strong>(num time) <a class="anchor-link" href="#advance"
              title="Permalink to Sweep.advance">#</a></h4>
<div class="doc">
<p>Advances the sweep forward, resulting in a new initial state.
Time is the new initial time.</p>
<pre class="source">
void advance(num time) {
 centerZero.x = (1 - time) * centerZero.x + time * center.x;
 centerZero.y = (1 - time) * centerZero.y + time * center.y;
 angleZero = (1 - time) * angleZero + time * angle;
}
</pre>
</div>
</div>
<div class="method"><h4 id="getTransform">
<button class="show-code">Code</button>
void <strong>getTransform</strong>(<a href="../box2d/Transform.html">Transform</a> xf, num alpha) <a class="anchor-link" href="#getTransform"
              title="Permalink to Sweep.getTransform">#</a></h4>
<div class="doc">
<p>Computes the interpolated transform at a specific time.
Time is the normalized time in <code>0,1</code>.</p>
<pre class="source">
void getTransform(Transform xf, num alpha) {
 assert (xf != null);

 xf.position.x = (1.0 - alpha) * centerZero.x + alpha * center.x;
 xf.position.y = (1.0 - alpha) * centerZero.y + alpha * center.y;
 xf.rotation.setRotation((1.0 - alpha) * angleZero + alpha * angle);

 // Shift to origin
 xf.position.x -= xf.rotation.col0.x * localCenter.x + xf.rotation.col1.x
     * localCenter.y;
 xf.position.y -= xf.rotation.col0.y * localCenter.x + xf.rotation.col1.y
     * localCenter.y;
}
</pre>
</div>
</div>
<div class="method"><h4 id="normalize">
<button class="show-code">Code</button>
void <strong>normalize</strong>() <a class="anchor-link" href="#normalize"
              title="Permalink to Sweep.normalize">#</a></h4>
<div class="doc">
<pre class="source">
void normalize() {
 num d = MathBox.TWO_PI * (angleZero / MathBox.TWO_PI).floor();
 angleZero -= d;
 angle -= d;
}
</pre>
</div>
</div>
<div class="method"><h4 id="setFrom">
<button class="show-code">Code</button>
void <strong>setFrom</strong>(<a href="../box2d/Sweep.html">Sweep</a> other) <a class="anchor-link" href="#setFrom"
              title="Permalink to Sweep.setFrom">#</a></h4>
<div class="doc">
<p>Sets this Sweep equal to the given Sweep.</p>
<pre class="source">
void setFrom(Sweep other) {
 localCenter.copyFrom(other.localCenter);
 centerZero.copyFrom(other.centerZero);
 center.copyFrom(other.center);
 angleZero = other.angleZero;
 angle = other.angle;
}
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
